package com.ht.modules.system.service.impl;

import com.ht.modules.system.entity.CommonConfig;
import com.ht.modules.system.entity.CommonConfigVo;
import com.ht.modules.system.mapper.CommonConfigMapper;
import com.ht.modules.system.service.ICommonConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 系统通用配置
 */
@Service
public class CommonConfigServiceImpl extends ServiceImpl<CommonConfigMapper, CommonConfig> implements ICommonConfigService {

    @Autowired
    private CommonConfigMapper commonConfigMapper;

    @Override
    public Page<CommonConfigVo> list(Page<CommonConfigVo> page, CommonConfigVo commonConfigVo,
                                     String column, String order) {
        return page.setRecords(commonConfigMapper.list(page, commonConfigVo, column, order));
    }

    @Override
    public void edit(CommonConfig commonConfig) {
        CommonConfig commonConfigEntity = this.getById(commonConfig.getId());
        if (commonConfigEntity == null){
            throw new RuntimeException("未找到对应实体！");
        }
        this.updateById(commonConfig);
    }

    @Override
    public CommonConfig queryById(String id) {
        CommonConfig commonConfig = this.getById(id);
        if (commonConfig == null){
            throw new RuntimeException("未找到对应实体！");
        }
        return commonConfig;
    }

    @Override
    public CommonConfigVo getUniqueConfig() {
        CommonConfigVo uniqueConfig = commonConfigMapper.getUniqueConfig();
        if(uniqueConfig==null) {
            uniqueConfig = new CommonConfigVo();
        }
        return uniqueConfig;
    }

}
